<?php
namespace App\Http\Controllers\Admin;

use App\AppChannel;
use App\BlackAccessLog;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class BlackAccessLogController extends Controller
{
    /**
     * @Desc: 黑名单访问列表
     * @Author: hank <maokeyang1031@gmail.com>
     * @param Request $request
     * @return \Illuminate\View\View
     */
    public function logList(Request $request)
    {
        $wd = $request->input('source_type', '');
        $appId = $request->input('app_id');
        $channelId = $request->input('channel_id', 0);
        $accessDate = $request->input('access_date', '');

        $model = BlackAccessLog::where("app_id", $appId);

        if (!empty($wd)) {
            $model->where("source_type", $wd);
        }

        if (!empty($accessDate)) {
            $model->where("access_date", $accessDate);
        }

        if (!empty($channelId)) {
            $model->where("channel_id", $channelId);
        }

        $channels = AppChannel::where("app_id", $appId)->get(["id", "name"]);

        $list = $model->with(["userApp", "appChannel", "blackRefer"])->orderBy("id", "desc")->paginate(10);

        return view('admin.black_access_log.index', ['list' => $list, 'wd' => $wd,
                                            "channels" => $channels, 'accessDate' => $accessDate,
                                            'appId' => $appId, 'channelId' => $channelId]);
    }
}
